home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-06 | 4.8 KB | 175 lines | [TEXT/CWIE] |
- // Program Author: Paul Baxter
- // pbaxter@assistivetech.com
- //
- //
- #include <Speech.h>
- #include <Ctype.h>
- #include <DeskBus.h>
- #include <Retrace.h>
-
- #include "pref.h"
- #include "globals.h"
- #include "menu.h"
- #include "aeutils.h"
- #include "aesetdata.h"
- #include "aetoken.h"
- #include "command.h"
-
- // * ****************************************************************************** *
- // * DoSetData
- // * Handles the SetData Apple Event, extracting the direct
- // * object (which says what to set) and the data (what to set
- // * it to).
- // * ****************************************************************************** *
- pascal OSErr DoSetData(const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefCon)
- {
- #pragma unused (reply, handlerRefCon)
- AEDesc directObj = {typeNull, NULL},
- dataDesc = {typeNull, NULL};
- OSErr err;
-
- // pick up the direct object, which is the object whose data is to be set
- err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeWildCard, &directObj);
- if (noErr != err) goto done;
-
- // now the data to set it to - typeWildCard means get as is
- // e.g. this is the name of the font for text
- err = AEGetParamDesc(theAppleEvent, keyAEData, typeWildCard, &dataDesc);
- if (noErr != err) goto done;
-
- // missing any parameters?
- err = GotRequiredParams(theAppleEvent);
- if (noErr != err) goto done;
-
- // set the data
- err = HandleSetData(&directObj, &dataDesc);
-
- done:
- if (directObj.dataHandle)
- AEDisposeDesc(&directObj);
- if (dataDesc.dataHandle)
- AEDisposeDesc(&dataDesc);
-
- return(err);
- } // DoSetData
-
-
- // * ****************************************************************************** *
- // * HandleSetData
- // * Resolves the object into a token (could be one of
- // * many) andthe sets the data of that object to dataDesc.
- // * ****************************************************************************** *
- OSErr HandleSetData(const AEDesc *theObj, AEDesc *dataDesc)
- {
- AEDesc objTokenDesc = {typeNull, NULL},
- itemDesc = {typeNull, NULL},
- ignoreResult = {typeNull, NULL};
- long index;
- DescType returnedType;
- OSErr err;
-
-
- // Coerce theObj into a token which we can use -
- // set the property or data for that token
- if (typeObjectSpecifier == theObj->descriptorType)
- err = AEResolve(theObj, kAEIDoMinimum, &objTokenDesc);
- else // Otherwise, just copy it
- err = AEDuplicateDesc(theObj, &objTokenDesc);
-
- if (noErr != err) goto done;
-
- switch (objTokenDesc.descriptorType) {
-
- case typeMyApplProp:
- err = SetAppProperty(&objTokenDesc, dataDesc);
- break;
-
- case typeAEList: // If it's a list then do each item
- err = AECountItems(&objTokenDesc, &index);
- if (noErr != err) goto done;
-
- for (; index > 0; index--) {
- err = AEGetNthDesc(&objTokenDesc, index, typeWildCard, &returnedType, &itemDesc);
-
- if (noErr == err) // Get property by calling this function again
- err = HandleSetData(&itemDesc, dataDesc);
-
- if (itemDesc.dataHandle)
- AEDisposeDesc(&itemDesc);
- }
- break;
-
- default:
- err = errAEWrongDataType;
- }
-
- done:
- if (objTokenDesc.dataHandle)
- AEDisposeDesc(&objTokenDesc);
- if (itemDesc.dataHandle)
- AEDisposeDesc(&itemDesc);
- if (ignoreResult.dataHandle)
- AEDisposeDesc(&ignoreResult);
-
- return(err);
- } // HandleSetData
-
-
- // * ****************************************************************************** *
- // * SetAppProperty
- // * Sets the property specified in theAPPPropToken to
- // * be that supplied in dataDesc.
- // * ****************************************************************************** *
- OSErr SetAppProperty(const AEDesc *theWPTokenDesc, const AEDesc *dataDesc)
- {
- ApplPropToken theAPPPropToken;
- AEDesc aDesc = {typeNull, NULL},
- ignoreResult = {typeNull, NULL};
- Size tokenSize;
- long value;
- Str255 newvoice;
- OSErr err;
-
- err = AECoerceDesc(theWPTokenDesc, typeMyApplProp, &aDesc);
- if (!err) {
-
- GetRawDataFromDescriptor(&aDesc, (Ptr)&theAPPPropToken,
- sizeof(theAPPPropToken), &tokenSize);
-
- switch (theAPPPropToken.tokenApplProperty) {
- case typeVoiceProperty:
- err = GetPStringFromDescriptor(dataDesc, newvoice);
- if (!err) {
- ProcessCommand(CHANGEVALUE(VoiceCmd, kStringValue), newvoice);
- }
- break;
-
- case typeSpeakCharProperty:
- err = GetLongIntFromDescriptor(dataDesc, &value);
- if (!err) {
- ProcessCommand(CHANGEVALUE(SpeakCharsCmd, value), nil);
- }
- break;
-
- case typeSpeakWordProperty:
- err = GetLongIntFromDescriptor(dataDesc, &value);
- if (!err) {
- ProcessCommand(CHANGEVALUE(SpeakWordsCmd, value), nil);
- }
- break;
-
- case typeSpeakSentenceProperty:
- err = GetLongIntFromDescriptor(dataDesc, &value);
- if (!err) {
- ProcessCommand(CHANGEVALUE(SpeakSentencesCmd, value), nil);
- }
- break;
- }
- }
- if (aDesc.dataHandle)
- AEDisposeDesc(&aDesc);
- if (ignoreResult.dataHandle)
- AEDisposeDesc(&ignoreResult);
- return err;
- }
-